<?
// MyMyUNSW: global definitions
// Written: John Shepherd, May 2008
// Last Modified: John Shepherd, May 2009
// This file must be included at the start of all scripts

// Global constants

define("SYSNAME","Interact");
define("DBCONN","host=localhost port=5432 dbname=thesis user=postgres password=password");
define("PATH","thesis");
//define("BASE","http://localhost:8080");
define("BASE","http://192.168.1.2:8080");
//define("BASE","http://149.171.226.207:8080/");
//define("BASE","http://jongles.dontexist.com");
define("ROOT",$_SERVER['DOCUMENT_ROOT']);
define("LOG",$_SERVER['DOCUMENT_ROOT']);

define("URL",BASE."/".PATH);
define("LIB",ROOT."/".PATH."/lib");

// Important libraries which are always included

require_once(LIB."/db.php");
require_once(LIB."/http.php");
require_once(LIB."/html.php");
require_once(LIB."/skin.php");
require_once(LIB."/session.php");

setTimer();

# libs: include a bunch of libraries
# - library names supplied as arguments
# - names containing / or .php are assumed to be local libraries
# - all other names are assumed to be libraries from SYS/lib

function libs()
{
	$libs = func_get_args();
	foreach ($libs as $lib)
	{
		if (strstr($lib,'/') || (strstr($lib,'.php')))
			$libFile = $lib;
		else
			$libFile = LIB."/$lib.php";
		require_once("$libFile");
	}
}

# def: checks whether a variable is defined
# - treats null and "" the same
# - if $index is defined, treat $var as array and check def($var[$index])

function def($var)
{
	return (isset($var) && !is_null($var) && $var != "");
}

# log: write an entry to a log file

function writeLog($log,$msg)
{
        $logfile = LOG."/$log";
        $f = fopen($logfile,"a");
        fwrite($f, "==== $_SERVER[SCRIPT_NAME] @ ".
                        date("d M Y H:i:s")."\n$msg\n");
        fclose($f);
}

# errorPage: write error output and halt

function errorPage($loc="Error",$msg="Invalid Operation")
{
	echo startPage($loc),
		"<center>",p(err($msg)),backLink(),"</center>\n",
		endPage();
	exit(0);
}

?>
